package com.zjitc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/*
    @Author:蔡志坚
    @Date: 2025/6/11 09:47
*/public class AdminIsLoginInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception{
        HttpSession session = request.getSession();
        String aname = (String) session.getAttribute("aname");
        if(aname == null || aname.length() == 0){
            request.setAttribute("erroMessage","没登录,无权访问,请登录！");
            request.getRequestDispatcher("/admin/toLogin").forward(request,response);
            return false;
        }
        return true;
    }
}
